package kr.saeildamil.androidstudty.ch19;

import kr.saeildamil.androidstudty.R;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;

public class PostTest extends Activity {
	int mMainValue;
	int mBackValue;

	TextView mMain;
	TextView mBack;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch19_tbreadtest);

		mMain = (TextView) findViewById(R.id.ch19_mainvalue);
		mBack = (TextView) findViewById(R.id.ch19_backvalue);

		BackThread thread = new BackThread();
		thread.setDaemon(true);
		thread.start();
	}

	public void mOnClick(View v) {
		mMainValue++;
		mMain.setText("Main Value : " + mMainValue);

	}

	class BackThread extends Thread {
		@Override
		public void run() {
			super.run();
			while (true) {
				mBackValue++;
				mHandler.post(new Runnable() {

					@Override
					public void run() {
						mBack.setText("Back Value : " + mBackValue);
					}
				});
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}
	}

	Handler mHandler = new Handler();

}
